package com.itheima.demo05stream;

import org.junit.Test;

import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Demo04StreamFunction {

    @Test
    public void testContact(){
        Stream<String> streamA = Stream.of("张三");
        Stream<String> streamB = Stream.of("李四");

        //合并成一个流
        Stream<String> newStream = Stream.concat(streamA, streamB);
        newStream.forEach(System.out::println);
    }

    @Test
    public void testNumbericStream(){
        //Integer占用的内存比int多，在Stream流操作中会自动装箱和拆箱
        Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5);
        //把大于3的打印出来
        stream.filter(n->n>3).forEach(System.out::println);

        //IntStream mapToInt(ToIntFunction<? super T> mapper);
        IntStream intStream = Stream.of(1, 2, 3, 4, 5).mapToInt(Integer::intValue);
        intStream.filter(n->n>3).forEach(System.out::println);

    }
}
